package com.hibase.core.rule.service.ruleexecute;


import com.hibase.core.rule.entity.ruledebug.RuleCallParamVO;
import com.hibase.core.rule.entity.ruledebug.RuleDebugParamVO;
import com.hibase.core.rule.entity.ruledebug.RuleDebugResultVO;
import com.hibase.core.rule.entity.ruledebug.RuleExecuteParamVO;
import com.hibase.core.rule.entity.rulemenu.RuleMenuContent;

import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;

/**
 * 描述:
 * 规则debug接口
 *
 * @author li-wei-hua
 * @date 2020-03-19 14:02
 */
public interface RuleExecuteService {

    /**
     * 规则调试
     *
     * @param paramVO
     * @return
     */
    RuleDebugResultVO debug(RuleDebugParamVO paramVO);


    Object executeRule(RuleExecuteParamVO paramVO) throws Exception;

    Object executeRule(RuleMenuContent content, Map<String, Object> map) throws Exception;

    /**
     * 执行查询sql
     *
     * @param dataSourceName 数据连接名称
     * @param sqlStr         sql语句
     * @param args           变量参数
     * @return remarks:
     * <li>2022年1月25日 by Xiong Liyi</li>
     * 变量参数:当可变参数类型为Map时用于匹配 #{AND LOC.WAREHOUSE_ID1 = [仓库序号1] }
     * <p>
     * params 参数格式: Map<仓库序号,202201250001>
     */
    List<Map<String, Object>> executeSelectSql(String dataSourceName, String sqlStr, Object... args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException;

    /**
     * 执行查询sql (debug)
     *
     * @param dataSourceName 数据连接名称
     * @param sqlStr         sql语句
     * @param args           变量参数
     * @return
     */
    List<Map<String, Object>> executeSelectSqlDebug(String dataSourceName, String sqlStr, Object... args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException;

    /**
     * 获取数据集结果
     *
     * @param dataSetName 数据集名称
     * @param args        参数数组
     * @return
     */
    List<Map<String, Object>> getDataSet(String dataSetName, Object... args);

    /**
     * 根据规则名称调用规则
     *
     * @param paramVO
     * @return
     */
    Object callRule(RuleCallParamVO paramVO) throws Exception;

    /**
     * 根据规则名称调用规则
     *
     * @param ruleName
     * @param paramMap
     * @return
     */
    Object callRule(String ruleName, Map<String, Object> paramMap) throws Exception;

    /**
     * 根据规则名称调用子规则
     *
     * @param ruleName
     * @param map
     * @return
     */
    Object callChildRule(String ruleName, Map<String, Object> map) throws Exception;


    /**
     * 查询规则表
     *
     * @param ruleName
     * @param objects
     * @return
     */
    List<Object> getRuleData(String ruleName, Object[] objects);

    /**
     * 查询规则表 第二版
     *
     * @param ruleName
     * @param objects
     * @return
     */
    List<Object> getRuleData2(String ruleName, Object[] objects);

    /**
     * 查询规则表 第三版
     *
     * @param ruleName
     * @param objects
     * @return
     */
    List<Map<String, String>> getRuleData3(String ruleName, Object time, Object[] objects);

    /**
     * 查询规则表唯一值
     *
     * @param ruleName
     * @param objects
     * @return
     */
    Map getOneRuleData(String ruleName, Object time, Object[] objects);


    /**
     * 查询规则表优先级
     *
     * @param ruleName
     * @param objects
     * @return
     */
    List<Map<String, String>> getPriorityRuleData(String ruleName, Object[] objects);

    /**
     * 查询规则表结果 并把json转 map
     *
     * @param ruleName
     * @param objects
     * @return
     */
    List<Map<String, String>> getRuleDataResult(String ruleName, Object[] objects);
}
